/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.cam.can.generalisator;

import java.util.Random;

/**
 *
 * @author Thomas
 */
public class GenMarStatus implements Generalisator{
    
    private String[] single = {"Never-married", "Divorced", "Widowed", "Separated"};
    private String[] married = {"Married-civ-spouse", "Married-AF-spouse", "Married-spouse-absent"};
    
    @Override
    public String gen(String value){
        for(String target : single){
            if(value.contains(target))
                return "SINGLE";
        }
        for(String target : married){
            if(value.contains(target))
                return "MARRIED";
        }
        return "*";
    }
    
    @Override
    public int getMaxGeneralisation() {
        return 3;
    }

    @Override
    public double getLength(String value) {
        if(value.equals("*"))
            return 3.0;
        for(String target : single){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : married){
            if(value.contains(target))
                return 1.0;
        }
        return 2.0;
    }

    @Override
    public double getMaxLength() {
        return 3.0;
    }

    @Override
    public String getUngeneralisation(String value) {
        Random rand = new Random(System.nanoTime());
        if(value.equals("*"))
            return "MARRIED";
        if(value.equals("SINGLE"))
           return single[rand.nextInt(single.length)];
        else
           return married[rand.nextInt(married.length)];
    }

    @Override
    public int getGeneralisationLevel(String value) {
        if(value.equals("*"))
            return 2;
        for(String target : single){
            if(value.contains(target))
                return 0;
        }
        for(String target : married){
            if(value.contains(target))
                return 0;
        }
        return 1;
    }
}
